<template>
  <a-modal
    title="资费定义"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="ant-modal-cust-warp"
    style="top: 5%; height: 85%; overflow-y: hidden"
    :footer="null"
  >
    <a-spin :spinning="confirmLoading">
      <detail-list title="">
        <detail-list-item term="项目编号"> {{ model.projectCode }}</detail-list-item>
        <detail-list-item term="项目名称"> {{ model.projectName }}</detail-list-item>
      </detail-list>
      <a-divider/>
      <SettingForm v-if="visible" @close="close" :model="model"/>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction, getAction, postAction } from '@/api/manage'
import DeptBaseInfoVue from '../system/modules/DeptBaseInfo.vue'
import DetailList from '@/components/tools/DetailList'
import SettingForm from './modules/SettingForm.vue';
const DetailListItem = DetailList.Item

export default {
  components: {
    DetailList,
    DetailListItem,
    SettingForm,
  },
  name: 'Setting',
  data() {
    return {
      title: '操作',
      visible: false,
      model: {},
      layout: {
        labelCol: { span: 3 },
        wrapperCol: { span: 14 },
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        exSection: {
          list: '/exProject/exProject/queryExSectionByMainId',
        },
        exChargeSetting: {
          queryByProjectId: '/exChargeSetting/exChargeSetting/queryByProjecrtId',
          save: '/exChargeSetting/exChargeSetting/save',
        },
      },
      columns: [
        {
          title: '标段名称',
          dataIndex: 'bidSectionName',
          key: 'bidSectionName',
          width: '20%',
          scopedSlots: { customRender: 'bidSectionName' },
        },
        {
          title: '计算方式',
          dataIndex: 'computeMethod',
          key: 'computeMethod',
          width: '20%',
          scopedSlots: { customRender: 'computeMethod' },
        },
        {
          title: '金额(元)',
          dataIndex: 'amount',
          key: 'amount',
          width: '20%',
          scopedSlots: { customRender: 'amount' },
        },
      ],
      exChargeSettingInfo: {
        id: '',
        projectId: '',
        projectCode: '',
        projectName: '',
        bsfIsSq: 0,
        tbbzjIsSq: 0, //投标保证金
        tbbzjIsTh: 0, //投标保证金是否退还
        tbbzjSqfs: 0, //投标保证金收取方式
        tbbzjJsfs: 0, //计算方式
        tbbzjIsBhsq: 0, //是否支持保函收取
        status: 0,
      },
      exSectionList: [],
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk(status) {
      const that = this
      var param = Object.assign({}, this.exChargeSettingInfo)
      param.status = status
      param.projectId = that.model.projectId
      param.projectCode = that.model.projectCode
      param.projectName = that.model.projectName
      param.exSectionList = that.exSectionList
      postAction(this.url.exChargeSetting.save, param).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.close()
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    handleChange(value, key, column) {
      const newData = [...this.exSectionList]
      const target = newData.filter((item) => key === item.id)[0]
      if (target) {
        target[column] = value
        this.exSectionList = newData
      }
    },
    handleCancel() {
      this.close()
    },
    loadList() {
      var that = this
      let params = { id: that.model.projectId }
      getAction(this.url.exSection.list, params)
        .then((res) => {
          if (res.success) {
            this.exSectionList = res.result
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    loadExChargeSettingInfo() {
      var that = this
      let params = { projectId: that.model.projectId }
      getAction(this.url.exChargeSetting.queryByProjectId, params)
        .then((res) => {
          if (res.success) {
            if (res.result) {
              Object.assign(that.exChargeSettingInfo, res.result)
              var items = ['bsfIsSq', 'tbbzjIsSq', 'tbbzjIsTh', 'tbbzjSqfs', 'tbbzjJsfs', 'tbbzjIsBhsq']
              items.forEach((e) => {
                that.exChargeSettingInfo[e] = parseInt(that.exChargeSettingInfo[e])
              })
            }
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
  },
}
</script>

<style scoped>
</style>
